home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 6858 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.1 KB

  1. Path: power2.powernet.co.uk!usenet
  2. From: dean@bugboy.powernet.co.uk (Dean Barrett)
  3. Newsgroups: comp.lang.c++
  4. Subject: Newbie help please !!!!!!
  5. Date: Fri, 16 Feb 1996 18:57:53 GMT
  6. Organization: Power Internet
  7. Message-ID: <4g2k9s$895@power2.powernet.co.uk>
  8. Reply-To: dean@bugboy.powernet.co.uk
  9. NNTP-Posting-Host: bugboy.powernet.co.uk
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. Can any body please help with probably a very simple problem, 
  13. part of program below shows data being written to then retreaved from
  14. file - I can get data to disk fine with each item on seperate lines
  15. but when i retreive it all goes horribly wrong!!.  If i use
  16. From_file<< to get data it works like cin so I lose strings with
  17. spaces - book im reading says you can use gets() and puts() to 
  18. write data but I cant work this out - any help greatly appreciated
  19. please email dean@bugboy.powernet.co.uk --
  20.  
  21. thanks in anticipation.
  22.  
  23. Dean Barrett.
  24.  
  25. void Bank_account::File_write()
  26. {
  27.    //data below obtained using gets and cin from user..
  28.     To_file.open(Acc_no,ios::out);
  29.     strcat(Acc_no,"\n");
  30.     strcat(Name,"\n");
  31.     strcat(Address,"\n");
  32.     To_file<<Acc_no;
  33.     To_file<<Name;
  34.     To_file<<Address;
  35.     To_file<<Balance;
  36.     To_file.close();
  37.     };
  38.  
  39.  
  40. void Bank_account::File_get()
  41. {
  42.     //Tried this From_file get but doesnt work quite right
  43.     char Delim='\n';
  44.     cout<<"Enter account No.\n";
  45.     cin>>Acc_no;
  46.     From_file.open(Acc_no,ios::in);
  47.     if (From_file.good())
  48.     {
  49.         
  50.         From_file.get(Acc_no,9,Delim);
  51.         cout<<Acc_no<<"\n";
  52.         From_file.get(Name,25,Delim);
  53.         cout<<Name<<"\n";
  54.         From_file.get(Address,40,Delim);
  55.         cout<<Address<<"\n";
  56.         From_file>>Balance;
  57.         cout<<Balance<<"\n";
  58.         From_file.close();
  59.     }
  60.     else
  61.     {
  62.         cout<<"This account does not exist\ncreate new \n";
  63.         cout<<"Enter name\n";
  64.         cout.flush();
  65.         gets(Name);
  66.         cout<<"Enter 1st line of address\n";
  67.         cout.flush();
  68.         gets(Address);
  69.         fflush(stdin);
  70.         cout<<"Enter opening Balance\n";
  71.         cin>>Balance;
  72.         cout.flush();
  73.         fflush(stdin);
  74.             
  75.         }
  76.         
  77.     
  78.     
  79.     };
  80.  
  81.  
  82.  
  83.